extends CollisionObject2D

@onready var sprite_default = $SpriteDefault
@onready var coin = $coin
const COIN = preload("res://asserts/sound/coin.ogg")

# Rect2(384,0,16,16) 默认box 
# Rect2(432,0,16,16) 触发完成后的box

var remain_coins = 3
		
func collect_coin():
	if remain_coins > 0:
		remain_coins -= 1;
		coin.get_node("AnimationPlayer").play("collect")
		$AudioStreamPlayer.play()
		print("get 1 coin!")
	if remain_coins == 0:
		sprite_default.region_rect = Rect2(432,0,16,16);
		
func _on_coin_box_body_entered(body):
	print(body.name + "body_entered!")
	if body.name == "CollisionShape2D":
		pass
	if remain_coins > 0:
		remain_coins = max(0,remain_coins-1);
		coin.get_node("AnimationPlayer").play("collect")
		$AudioStreamPlayer.play()
		print("get 1 coin!")
	if remain_coins == 0:
		sprite_default.region_rect = Rect2(432,0,16,16);
